<?php


namespace app\api\controller\v1;

use app\api\service\Token as TokenService;
use app\api\controller\BaseController;
use app\api\model\User as UserModel;
use app\common\exception\UserException;
use app\common\message\SuccessMessage;

class Base extends BaseController
{
    protected function getCurrentUser()
    {
        $uid = TokenService::getCurrentUID();
        $user = UserModel::get($uid);
        if(empty($user))
        {
            throw new UserException();
        }
        return $user;
    }

    //user 和 admin 有权访问
    protected function checkPrimaryScope()
    {
        echo "checkPrimaryScope 方法";
        return TokenService::needPrimaryScope();
    }

    // user有权访问
    protected function checkExclusiveScope()
    {
        echo 'checkExclusiveScope 方法';
        return TokenService::needExclusiveScope();
    }

    protected function ok($data){
        $res = new SuccessMessage($data);
        return json($res, 200)->send();
    }

    protected function fail(){
        return json([], 200)->send();
    }
}